home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group01b.txt / 000077_icon-group-sender_Tue Jun 19 13:15:51 2001.msg < prev    next >
Internet Message Format  |  2002-01-03  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id f5JKDd612699
  4.     for icon-group-addresses; Tue, 19 Jun 2001 13:13:39 -0700 (MST)
  5. Message-Id: <200106192013.f5JKDd612699@baskerville.CS.Arizona.EDU>
  6. Date: Tue, 19 Jun 2001 08:24:44 -0700
  7. From: Steve Wampler <swampler@noao.edu>
  8. X-Accept-Language: en
  9. To: deborah_fairwater@hotmail.com
  10. CC: icon-group@cs.arizona.edu
  11. Subject: Re: code needed!
  12. Errors-To: icon-group-errors@cs.arizona.edu
  13. Status: RO
  14. Content-Length: 1912
  15.  
  16. Chris.D.Tenaglia@jci.com wrote:
  17. > #
  18. > # file : padsent.icn
  19. > # desc : add extra space to end of each sentence
  20. > # use : padsent <infile >outfile
  21. > #
  22. > procedure main()
  23. >     while line := read() do
  24. >         {
  25. >         work := reverse(line)
  26. >         text   := ""
  27. >         every i := 1 to *work do
  28. >      {
  29. >                 text ||:= work[i]
  30. >      if (work[i] == " ") & (work[i+1] == ".") then text ||:= " "
  31. >                 if (work[i] == " ") & (work[i+1] == "?") then text ||:= " "
  32. >                 if (work[i] == " ") & (work[i+1] == "!") then text ||:= " "
  33.  
  34. Just to show an alternative formulation, the above three lines lines could
  35. also be written as:
  36.  
  37.        if work[i+:2] == (" ." | " ?" | " !") then text ||:= " "
  38.  
  39. But a full-up string scanning solution might be useful and wouldn't need
  40. the string reversals:
  41.  
  42. # Danger, Will Robinson - untested code follows!
  43.  
  44. procedure main()
  45.     every write(repair(!&input))
  46. end
  47.  
  48. procedure repair(line, sentenceEnders)
  49.     # setup default sentence-ending punctuation if 2nd argument is missing
  50.     /sentenceEnders := '.?!'
  51.  
  52.     s := ""
  53.     line ? {
  54.         while s ||:= tab(upto(sentenceEnders)) || move(1) do {
  55.             # Don't add a second blank if it's already there
  56.             s ||:= =" " || (=" " | " ")
  57.             }
  58.         s ||:= tab(0)
  59.         }
  60.     return s
  61. end
  62.  
  63. >      }
  64. >         write(reverse(text))
  65. >         }
  66. >   end
  67. >                     deborah_fairwater@h
  68. >                     otmail.com                 To:     icon-group@CS.Arizona.EDU
  69. >                                                cc:
  70. >                     06/16/01 03:53 PM          Subject:     code needed!
  71. > Help - I need the icon code that will look at an input text file and
  72. > replace single spaces between sentences with double spaces - can anyone
  73. > help?
  74. > Thank you.
  75.  
  76. --
  77. Steve Wampler-  SOLIS Project, National Solar Observatory
  78. swampler@noao.edu
  79.